package com.jinzhi.jzweb.controller;



import java.math.BigDecimal;

import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import cn.afterturn.easypoi.excel.entity.ExportParams;
import cn.afterturn.easypoi.word.WordExportUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.jinzhi.common.bo.LogBO;
import com.jinzhi.common.service.LogService;
import com.jinzhi.common.type.EnumErrorCode;
import com.jinzhi.common.utils.*;
import com.jinzhi.jzweb.domain.ExaminationBatchDO;
import com.jinzhi.jzweb.domain.ExaminationCostDO;
import com.jinzhi.jzweb.domain.PublicRefundDO;
import com.jinzhi.jzweb.pojo.*;
import com.jinzhi.jzweb.pojo.bo.ExpenseTotalBO;
import com.jinzhi.jzweb.service.ArchivesService;
import com.jinzhi.jzweb.service.ExaminationBatchService;
import com.jinzhi.jzweb.service.ExaminationCostService;
import com.jinzhi.jzweb.utils.EasyPoiUtil;
import com.jinzhi.sys.domain.RoleDO;
import com.jinzhi.sys.domain.UserRoleDO;
import com.jinzhi.sys.service.RoleService;
import com.jinzhi.sys.service.UserRoleService;
import com.mysql.jdbc.StringUtils;
import lombok.experimental.var;
import lombok.val;
import org.apache.poi.ss.formula.functions.T;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.util.ResourceUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.jinzhi.common.annotation.Log;
import com.jinzhi.common.base.BaseController;
import com.jinzhi.jzweb.domain.RefundDO;
import com.jinzhi.jzweb.service.RefundService;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 
 * <pre>
 *  考试费返费录入
 * </pre>
 * <small> 2022-02-25 10:15:00 | lance</small>
 */
@Controller
@RequestMapping("/jzweb/refund")
public class RefundController extends BaseController {

	@Autowired
	private ExaminationBatchService examinationBatchService;
	@Autowired
	private RefundService refundService;
	@Autowired
	private RoleService roleService;
	@Autowired
	private ExaminationCostService examinationCostService;
	@Autowired
	private UserRoleService userRoleService;
	@Autowired
	private ArchivesService archivesService;
	@Autowired
	private LogService logService;

	@GetMapping()
	@RequiresPermissions("jzweb:refund:refund")
	String Refund(Integer year,Model model){

		model.addAttribute("year",year);
	    return "jzweb/refund/refund";
	}


	/**
	 * 选择导出判断
	 *
	 */
	@RequestMapping("/refndExcelRole")
	@RequiresPermissions("jzweb:refund:import")
	@ResponseBody
	@Transactional
	public Result<?> refndExcelRole(@RequestParam("ids[]") String[] ids) {
		List ids1=new ArrayList();
		Long roleId=0l;
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//获取用户系统权限
		Integer is = userRoleService.userRolenum(this.getUserId());

		for(String ll:ids){

			ids1.add(ll);
		}
		List<RefundDO> list = new ArrayList<>();
		List<RefundVO> listFile = new LinkedList<>();
		Map map=new HashMap();

		map.put("export",0);
		map.put("list",ids1);

		list=	refundService.listRefunds(map);

//		//如果批次id不同不能导出
//		Integer batchId =0;
//		if (null!=list){
//			batchId = list.get(0).getBatchId();
//		}
//		for (RefundDO refundDO:list){
//			if (!batchId.equals(refundDO.getBatchId())){
//				return Result.fail("导出时必须选择同一批次！");
//			}
//		}

//		if(is==8||is==9){
//			for(RefundDO li:list){
//				for(RefundDO li1:list){
//					if(!li.getId1().equals(li1.getId1())){
//						return Result.fail("普通用户只能导出同一批次");
//					}
//				}
//			}
//		}


		if(is==8||is==9||is==18||is==19){
			for(RefundDO li1:list){
				if (li1.getConfirmState()==null){
					return Result.fail("包含未确认的数据导出失败");
				}
				if (li1.getConfirmState()!=1){
					return Result.fail("包含未确认的数据导出失败");
				}
				if (null!=li1.getExport()) {
					if ("1".equals(String.valueOf(li1.getExport()))) {
						return Result.fail("该数据已导出");
					}
				}
			}
		}

		//导出操作
		return  Result.ok();
	}




	/**
	 * 选择导出 Excel版
	 *
	 */
	@RequestMapping("/refndExcel")
	@RequiresPermissions("jzweb:refund:import")
	@ResponseBody
    @Transactional
	public void refndExcel(@RequestParam("ids[]") Long[] ids,HttpServletResponse response) {
		List ids1=new ArrayList();
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//获取用户系统权限
		Integer is = userRoleService.userRolenum(this.getUserId());

		for(Long ll:ids){

			ids1.add(ll);
		}
		List<RefundDO> list = new ArrayList<>();
		List<RefundVO> listFile = new LinkedList<>();
		Map map=new HashMap();

		map.put("export",0);
		map.put("list",ids1);

		list=	refundService.listRefunds(map);

		for(RefundDO li:list){
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
			RefundVO refundVO=new RefundVO();
			refundVO.setBatchId(li.getBatchId());
			refundVO.setExpertName(li.getExpertName());
			refundVO.setExpertIdCard(li.getExpertIdCard());
			refundVO.setExpertType(li.getExpertType());
			refundVO.setExpertOrgName(li.getExpertOrgName());
			refundVO.setEvaluationTime(sdf.format(li.getEvaluationTime()));
			refundVO.setEvaluationSchool(li.getEvaluationSchool());
			refundVO.setProvince(li.getProvince());
			refundVO.setRegionUserName(li.getRegionUserName());
			refundVO.setLaborCost(li.getLaborCost());
			refundVO.setMeals(li.getMeals());
			refundVO.setTrafficExpense(li.getTrafficExpense());
			refundVO.setHotelExpense(li.getHotelExpense());
			refundVO.setPostage(li.getPostage());
			refundVO.setTrafficExpenseMax(li.getTrafficExpenseMax());
			refundVO.setSumExpense(li.getSumExpense());
			refundVO.setExpertOrgName(li.getExpertOrgName());
			refundVO.setBankAccount(li.getBankAccount());
			refundVO.setBankOfDeposit(li.getBankOfDeposit());
			refundVO.setRemarks(li.getRemarks());
			refundVO.setEvaluationNum(li.getEvaluationNum());
			refundVO.setLaborCostAveragePrice(li.getLaborCostAveragePrice());
			refundVO.setMobile(li.getMobile());
			//其它费用
			refundVO.setOtherCost(li.getOtherCost());
			if (li.getExamFeeIf()!=null){ //查询证书等级并导出
				ExaminationCostDO examinationCostDO = examinationCostService.selectById(li.getExamFeeIf());
				refundVO.setProfile(examinationCostDO.getProfile());
			}
//			if(li.getRefundType()==1){
//				refundVO.setRefundType("对私");
//			}else {
//				refundVO.setRefundType("对共");
//			}
//			if(li.getExport()==0){
//                listFile.add(refundVO);
//            }
			listFile.add(refundVO);
			if(is==8||is==9||is==18||is==19){
				li.setExport(1);
				li.setDeriveTime(new Date());
				refundService.updateById(li);
			}

		}

		ExportParams exportParams =new ExportParams();
		Date date=new Date();
		SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");

		ExpenseTotalBO expenseTotalBO = refundService.moneyTotal(map);
		expenseTotalBO = bigDecimalDef(expenseTotalBO);

		String msg="导出时间："+sdf.format(date)+" " +
				" （劳务费合计："+expenseTotalBO.getLaborCostTotal()+
				"） （餐费费合计："+expenseTotalBO.getMealsTotal()+"） （市内交通费合计："+expenseTotalBO.getTrafficExpenseTotal()+
				"） （住宿费合计："+expenseTotalBO.getHotelExpenseTotal()+"） （邮费合计："+expenseTotalBO.getPostageTotal()+
				"） （大交通费合计："+expenseTotalBO.getTrafficExpenseMaxTotal()+"） （其它费用："+expenseTotalBO.getOtherCostTotal()+
				"）" +
				"	总合计："+expenseTotalBO.getSumExpenseTotal();

		exportParams.setSecondTitle(msg);

		//导出操作
		//EasyPoiUtil.exportExcel(listFile, "考试费劳务费信息表", "劳务费信息（选择）", RefundVO.class, "考试费劳务费信息（选择）", response);

		setUserRefundwVO(listFile);


		EasyPoiUtil.exportExcel2(listFile, "考试费劳务费信息表", "劳务费信息（选择）", RefundVO.class, "考试费劳务费信息（选择）", response,exportParams);

	}



	//在excel最后封装签字属性
	private void setUserRefundwVO(List<RefundVO> listFile){
		RefundVO userRefundVO =new RefundVO();
		userRefundVO.setBankOfDeposit("区域考评负责人签字：");
		RefundVO userRefundVO2 =new RefundVO();
		userRefundVO2.setBankOfDeposit("经理签字：");
		RefundVO userRefundVO3 =new RefundVO();
		userRefundVO3.setBankOfDeposit("销售内勤签字：");
		RefundVO userRefundVO4 =new RefundVO();
		userRefundVO4.setBankOfDeposit("副总监签字：");
		RefundVO userRefundVO5 =new RefundVO();
		userRefundVO5.setBankOfDeposit("总监签字：");
		RefundVO userRefundVO6 =new RefundVO();
		userRefundVO6.setBankOfDeposit("  ");
		RefundVO userRefundVO7 =new RefundVO();
		userRefundVO7.setBankOfDeposit("  ");
		RefundVO userRefundVO8 =new RefundVO();
		userRefundVO8.setBankOfDeposit("  ");
		listFile.add(userRefundVO6);
		listFile.add(userRefundVO7);
		listFile.add(userRefundVO8);
		listFile.add(userRefundVO);
		listFile.add(userRefundVO2);
		listFile.add(userRefundVO3);
		listFile.add(userRefundVO4);
		listFile.add(userRefundVO5);
	}




//	/**
//	 * 选择导出 word
//	 *
//	 */
//	@RequestMapping("/refndExcel")
//	@RequiresPermissions("jzweb:refund:import")
//	@ResponseBody
//	@Transactional
//	public void refndExcel(@RequestParam("ids[]") Long[] ids,HttpServletResponse response) throws Exception {
//
//		//获取模板文档
//		File rootFile =new File(ResourceUtils.getURL("classpath:").getPath());
//		File templateFile= new File(rootFile,"/easypoi/refnd.docx");
//
//
//		List ids1=new ArrayList();
//		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
//		//获取用户系统权限
//		Integer is = userRoleService.userRolenum(this.getUserId());
//
//		for(Long ll:ids){
//
//			ids1.add(ll);
//		}
//		List<RefundDO> list = new ArrayList<>();
//		List<RefundVO> listFile = new LinkedList<>();
//		Map map=new HashMap();
//
//		map.put("export",0);
//		map.put("list",ids1);
//
//		list=	refundService.listRefunds(map);
//
//		int i=0;
//		for(RefundDO li:list){
//			i++;
//			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
//			RefundVO refundVO=new RefundVO();
//			refundVO.setBatchId(li.getBatchId());
//			refundVO.setExpertName(li.getExpertName());
//			refundVO.setExpertType(li.getExpertType());
//			refundVO.setEvaluationTime(sdf.format(li.getEvaluationTime()));
//			refundVO.setEvaluationSchool(li.getEvaluationSchool());
//			refundVO.setProvince(li.getProvince());
//			refundVO.setRegionUserName(li.getRegionUserName());
//			refundVO.setLaborCost(li.getLaborCost());
//			refundVO.setMeals(li.getMeals());
//			refundVO.setTrafficExpense(li.getTrafficExpense());
//			refundVO.setHotelExpense(li.getHotelExpense());
//			refundVO.setPostage(li.getPostage());
//			refundVO.setTrafficExpenseMax(li.getTrafficExpenseMax());
//			refundVO.setSumExpense(li.getSumExpense());
//			refundVO.setBankAccount(li.getBankAccount());
//			refundVO.setBankOfDeposit(li.getBankOfDeposit());
//			refundVO.setRemarks(li.getRemarks());
//			refundVO.setEvaluationNum(li.getEvaluationNum());
//			refundVO.setLaborCostAveragePrice(li.getLaborCostAveragePrice());
//			refundVO.setShowId(i);
//			//其它费用
//			refundVO.setOtherCost(li.getOtherCost());
//			listFile.add(refundVO);
//			if(is==8||is==9){
//				li.setExport(1);
//				li.setDeriveTime(new Date());
//				refundService.updateById(li);
//			}
//
//		}
//
//		Date date=new Date();
//		SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
//
//		ExpenseTotalBO expenseTotalBO = refundService.moneyTotal(map);
//		expenseTotalBO = bigDecimalDef(expenseTotalBO);
//
//		//对私导出组装数据
//		Map<String,Object> params =new HashMap<>();
//		params.put("wordEvaluationSchool",listFile.get(0).getEvaluationSchool());
//		params.put("wordEvTime",listFile.get(0).getEvaluationTime());
//		params.put("wordEvNum", listFile.get(0).getEvaluationNum());
//		params.put("wordSum", expenseTotalBO.getSumExpenseTotal());
//		params.put("wordEvaluationSchoolAndBatchId",listFile.get(0).getEvaluationSchool() + "(" + listFile.get(0).getBatchId()+")");
//		params.put("wordUnitName","湖南金职伟业母婴护理有限公司");
//		params.put("wordApplyTime",sdf.format(date));
//		params.put("listFile",listFile);
//
//
//		XWPFDocument word = WordExportUtil.exportWord07(templateFile.getPath(),params);
//		String filename = "2022劳务费信息表(选择).docx";
//		response.setHeader("content-disposition","attachment;filename="+new String(filename.getBytes(),"ISO8859-1"));
//		response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//		word.write(response.getOutputStream());
//	}







	/**
	 * 下载返费信息录入导入模板
	 *
	 * @param response
	 */
	@RequestMapping("/downloadImportTemplate")
	@RequiresPermissions("jzweb:refund:import")
	@ResponseBody
	public void downloadImportTemplate(HttpServletResponse response) {
		List<RefundVO1> list = new LinkedList<>();
		//导出操作
		EasyPoiUtil.exportExcel(list, "劳务费信息导入模板", "劳务费信息导入模板", RefundVO1.class, "劳务费信息详情导入模板", response);
	}






	/**
	 * 全部导出判断
	 *
	 */
	@RequestMapping("/exportFileRole")
	@RequiresPermissions("jzweb:refund:import")
	@ResponseBody
	@Transactional
	public Result<?> exportFileRole(RefundDO refundDTO) {
		Integer is = userRoleService.userRolenum(this.getUserId());
		List<RoleDO>  listRole=roleService.findAll();
		List<RefundDO> list = new LinkedList<>();
		List<RefundVO> listFile = new LinkedList<>();
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//查询所有用户所属权限

		Map map=new HashMap();
		Long chOO1=0l;
		Long chOO2=0l;
		if(is==6){
			List lists=new ArrayList();
			List list1s=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场一部")||roleDO.getRoleName().equals("市场一部管理员")){
					chOO1=roleDO.getId();
					lists.add(chOO1);
					//break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.in("roleId",lists);
			//Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);
			List <UserRoleDO> userRoleDOS =userRoleService.selectList(wrapper1);
			//List<UserRoleDO> userRoleDOS=	page1.getRecords();
			for(UserRoleDO users:userRoleDOS){
				list1s.add(users.getUserId());
			}
			map.put("list1",list1s);
		}else if(is==7){
			List lists=new ArrayList();
			List list1s=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场二部")||roleDO.getRoleName().equals("市场二部管理员")){
					chOO1=roleDO.getId();
					lists.add(chOO1);
					//break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.in("roleId",lists);
			List <UserRoleDO> userRoleDOS =userRoleService.selectList(wrapper1);
			for(UserRoleDO users:userRoleDOS){
				list1s.add(users.getUserId());
			}
			map.put("list1",list1s);
		}else if(is==8){
			map.put("list2",this.getUserId().toString());

		}else if(is==9){

			map.put("list2",this.getUserId().toString());
		}else if(is==18){
			map.put("list2",this.getUserId().toString());

		}else if(is==19){

			map.put("list2",this.getUserId().toString());
		}

		map.put("year",refundDTO.getYear());
		map.put("province",refundDTO.getProvince());
		map.put("refundRrNot",refundDTO.getRefundRrNot());
		map.put("batchId",refundDTO.getBatchId());
		map.put("batchId2",refundDTO.getBatchId2());
		map.put("id1",refundDTO.getId1());
		map.put("orgName",refundDTO.getSchoolName());
		map.put("expertName",refundDTO.getExpertName());
		map.put("expertIdCard",refundDTO.getExpertIdCard());
		map.put("evaluationSchool",refundDTO.getSchoolName());
		map.put("regionUserName",refundDTO.getRegionUserName());
		map.put("examStartDate",StringUtil.notEmpty(refundDTO.getExamStartDate())?refundDTO.getExamStartDate()+" 00:00:00":refundDTO.getExamStartDate());
		map.put("examEndDate",StringUtil.notEmpty(refundDTO.getExamEndDate())?refundDTO.getExamEndDate()+" 00:00:00":refundDTO.getExamEndDate());
		map.put("export",0);
		map.put("list",null);
		list=	refundService.listRefunds(map);

//		//如果批次id不同不能导出
//		Integer batchId =0;
//		if (null!=list){
//			batchId = list.get(0).getBatchId();
//		}
//		for (RefundDO refundDO:list){
//			if (!batchId.equals(refundDO.getBatchId())){
//				return Result.fail("导出时必须选择同一批次！");
//			}
//		}

		System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++共导出："+list.size());
		if(is==8||is==9||is==18||is==19){
			for(RefundDO li1:list){
				if (li1.getConfirmState()==null){
					return Result.fail("包含未确认的数据导出失败");
				}
				if (li1.getConfirmState()!=1){
					return Result.fail("包含未确认的数据导出失败");
				}
				if (null!=li1.getExport()) {
					System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++导出状态为："+li1.getExport());
					if (Integer.valueOf(1).equals(li1.getExport())) {
						System.out.println("+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++进入导出判断");
						return Result.fail("请勿重复导出");
					}
				}
			}
		}

		return  Result.ok();
	}






//	/**
//	 * 下载全部返费信息 word
//	 *
//	 * @param response
//	 */
//	@RequestMapping("/exportFile")
//	@RequiresPermissions("jzweb:refund:import")
//	@ResponseBody
//	public void exportFile(HttpServletResponse response,RefundDO refundDTO) throws Exception{
//
//		//获取模板文档
//
//		String filepath = Thread.currentThread().getContextClassLoader().getResource("").getPath();
//		File rootFile =new File(filepath);
//
////		File rootFile =new File(ResourceUtils.getURL("classpath:").getPath());
//
//		File templateFile= new File(rootFile,"/easypoi/refnd.docx");
//
//		System.out.println("word文件导出路径++++++++++++++++++++++++++++++++++++++++++++++++++++"+templateFile.toString());
//
//		Integer is = userRoleService.userRolenum(this.getUserId());
//		List<RoleDO>  listRole=roleService.findAll();
//		List<RefundDO> list = new LinkedList<>();
//		List<RefundVO> listFile = new LinkedList<>();
//		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
//		//查询所有用户所属权限
//
//		Map map=new HashMap();
//		Long chOO1=0l;
//		Long chOO2=0l;
//		if(is==6){
//			List lists=new ArrayList();
//			List list1s=new ArrayList();
//			for(RoleDO roleDO:listRole){
//				if(roleDO.getRoleName().equals("市场一部")||roleDO.getRoleName().equals("市场一部管理员")){
//					chOO1=roleDO.getId();
//					lists.add(chOO1);
//					//break;
//				}
//			}
//			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();
//
//			wrapper1.in("roleId",lists);
//			//Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);
//			List <UserRoleDO> userRoleDOS =userRoleService.selectList(wrapper1);
//			//List<UserRoleDO> userRoleDOS=	page1.getRecords();
//			for(UserRoleDO users:userRoleDOS){
//				list1s.add(users.getUserId());
//			}
//			map.put("list1",list1s);
//		}else if(is==7){
//			List lists=new ArrayList();
//			List list1s=new ArrayList();
//			for(RoleDO roleDO:listRole){
//				if(roleDO.getRoleName().equals("市场二部")||roleDO.getRoleName().equals("市场二部管理员")){
//					chOO1=roleDO.getId();
//					lists.add(chOO1);
//					//break;
//				}
//			}
//			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();
//
//			wrapper1.in("roleId",lists);
//			List <UserRoleDO> userRoleDOS =userRoleService.selectList(wrapper1);
//			for(UserRoleDO users:userRoleDOS){
//				list1s.add(users.getUserId());
//			}
//			map.put("list1",list1s);
//		}else if(is==8){
//			map.put("list2",this.getUserId().toString());
//
//		}else if(is==9){
//
//			map.put("list2",this.getUserId().toString());
//		}
//
//		map.put("year",refundDTO.getYear());
//		map.put("province",refundDTO.getProvince());
//		map.put("refundRrNot",refundDTO.getRefundRrNot());
//		map.put("batchId",refundDTO.getBatchId());
//		map.put("batchId2",refundDTO.getBatchId2());
//		map.put("id1",refundDTO.getId1());
//		map.put("orgName",refundDTO.getSchoolName());
//		map.put("expertName",refundDTO.getExpertName());
//		map.put("regionUserName",refundDTO.getRegionUserName());
//		map.put("examStartDate",StringUtil.notEmpty(refundDTO.getExamStartDate())?refundDTO.getExamStartDate()+" 00:00:00":refundDTO.getExamStartDate());
//		map.put("examEndDate",StringUtil.notEmpty(refundDTO.getExamEndDate())?refundDTO.getExamEndDate()+" 00:00:00":refundDTO.getExamEndDate());
//		map.put("export",0);
//		map.put("list",null);
//		list=	refundService.listRefunds(map);
//
//		for(RefundDO li:list){
//			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
//			RefundVO refundVO=new RefundVO();
//			refundVO.setBatchId(li.getBatchId());
//			refundVO.setExpertName(li.getExpertName());
//			refundVO.setExpertType(li.getExpertType());
//			refundVO.setEvaluationTime(sdf.format(li.getEvaluationTime()));
//			refundVO.setEvaluationSchool(li.getEvaluationSchool());
//			refundVO.setProvince(li.getProvince());
//			refundVO.setRegionUserName(li.getRegionUserName());
//			refundVO.setLaborCost(li.getLaborCost());
//			refundVO.setMeals(li.getMeals());
//			refundVO.setTrafficExpense(li.getTrafficExpense());
//			refundVO.setHotelExpense(li.getHotelExpense());
//			refundVO.setPostage(li.getPostage());
//			refundVO.setTrafficExpenseMax(li.getTrafficExpenseMax());
//			refundVO.setSumExpense(li.getSumExpense());
//			refundVO.setBankAccount(li.getBankAccount());
//			refundVO.setBankOfDeposit(li.getBankOfDeposit());
//			refundVO.setRemarks(li.getRemarks());
//			refundVO.setEvaluationNum(li.getEvaluationNum());
//			refundVO.setLaborCostAveragePrice(li.getLaborCostAveragePrice());
//			//其它费用
//			refundVO.setOtherCost(li.getOtherCost());
//			listFile.add(refundVO);
//			if(is==8||is==9){
//				li.setExport(1);
//				li.setDeriveTime(new Date());
//				refundService.updateById(li);
//			}
//		}
//
//
//		Date date=new Date();
//		SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");
//
//		ExpenseTotalBO expenseTotalBO = refundService.moneyTotal(map);
//		expenseTotalBO = bigDecimalDef(expenseTotalBO);
//
//
//
//		//对私导出组装数据
//		Map<String,Object> params =new HashMap<>();
//		params.put("wordEvaluationSchool",listFile.get(0).getEvaluationSchool());
//		params.put("wordEvTime",listFile.get(0).getEvaluationTime());
//		params.put("wordEvNum", String.valueOf(listFile.get(0).getEvaluationNum()));
//		params.put("wordSum", expenseTotalBO.getSumExpenseTotal());
//		params.put("wordEvaluationSchoolAndBatchId",listFile.get(0).getEvaluationSchool() + "(" + listFile.get(0).getBatchId()+")");
//		params.put("wordUnitName","湖南金职伟业母婴护理有限公司");
//		params.put("wordApplyTime",sdf.format(date));
//		params.put("listFile",listFile);
//
//
//		XWPFDocument word = WordExportUtil.exportWord07(templateFile.getPath(),params);
//		String filename = "2022劳务费信息表(批量).docx";
//		response.setHeader("content-disposition","attachment;filename="+new String(filename.getBytes(),"ISO8859-1"));
//		response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
//		word.write(response.getOutputStream());
//
//	}





	/**
	 * 下载全部返费信息
	 *
	 * @param response
	 */
	@RequestMapping("/exportFile")
	@RequiresPermissions("jzweb:refund:import")
	@ResponseBody
	public void exportFile(HttpServletResponse response,RefundDO refundDTO) {
		Integer is = userRoleService.userRolenum(this.getUserId());
		List<RoleDO>  listRole=roleService.findAll();
		List<RefundDO> list = new LinkedList<>();
		List<RefundVO> listFile = new LinkedList<>();
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//查询所有用户所属权限

		Map map=new HashMap();
		Long chOO1=0l;
		Long chOO2=0l;
		if(is==6){
			List lists=new ArrayList();
			List list1s=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场一部")||roleDO.getRoleName().equals("市场一部管理员")){
					chOO1=roleDO.getId();
					lists.add(chOO1);
					//break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.in("roleId",lists);
			//Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);
			List <UserRoleDO> userRoleDOS =userRoleService.selectList(wrapper1);
			//List<UserRoleDO> userRoleDOS=	page1.getRecords();
			for(UserRoleDO users:userRoleDOS){
				list1s.add(users.getUserId());
			}
			map.put("list1",list1s);
		}else if(is==7){
			List lists=new ArrayList();
			List list1s=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场二部")||roleDO.getRoleName().equals("市场二部管理员")){
					chOO1=roleDO.getId();
					lists.add(chOO1);
					//break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.in("roleId",lists);
			List <UserRoleDO> userRoleDOS =userRoleService.selectList(wrapper1);
			for(UserRoleDO users:userRoleDOS){
				list1s.add(users.getUserId());
			}
			map.put("list1",list1s);
		}else if(is==8){
			map.put("list2",this.getUserId().toString());

		}else if(is==9){

			map.put("list2",this.getUserId().toString());
		} else if(is==18){
			map.put("list2",this.getUserId().toString());

		}else if(is==19){

			map.put("list2",this.getUserId().toString());
		}

		map.put("year",refundDTO.getYear());
		map.put("province",refundDTO.getProvince());
		map.put("refundRrNot",refundDTO.getRefundRrNot());
		map.put("batchId",refundDTO.getBatchId());
		map.put("batchId2",refundDTO.getBatchId2());
		map.put("id1",refundDTO.getId1());
		map.put("orgName",refundDTO.getSchoolName());
		map.put("expertName",refundDTO.getExpertName());
		map.put("expertIdCard",refundDTO.getExpertIdCard());
		map.put("evaluationSchool",refundDTO.getSchoolName());
		map.put("regionUserName",refundDTO.getRegionUserName());
		map.put("examStartDate",StringUtil.notEmpty(refundDTO.getExamStartDate())?refundDTO.getExamStartDate()+" 00:00:00":refundDTO.getExamStartDate());
		map.put("examEndDate",StringUtil.notEmpty(refundDTO.getExamEndDate())?refundDTO.getExamEndDate()+" 00:00:00":refundDTO.getExamEndDate());
		map.put("export",0);
		map.put("list",null);
	    list=	refundService.listRefunds(map);


//	    //同一批次导出一次
//	    	if(is==8||is==9){
//				for(RefundDO li:list){
//					for(RefundDO li1:list){
//						if(!li.getId1().equals(li1.getId1())){
//							return ;
//						}
//					}
//				}
//			}

		//取出集合中第一个batchId
		Integer batchId = list.get(0).getBatchId();

		for(RefundDO li:list){
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
	    	RefundVO refundVO=new RefundVO();
	    	refundVO.setBatchId(li.getBatchId());
	    	refundVO.setExpertName(li.getExpertName());
			refundVO.setExpertIdCard(li.getExpertIdCard());
			refundVO.setExpertType(li.getExpertType());
			refundVO.setExpertOrgName(li.getExpertOrgName());
			//refundVO.setEvaluationTime(li.getEvaluationTime());
			refundVO.setEvaluationTime(sdf.format(li.getEvaluationTime()));
			refundVO.setEvaluationSchool(li.getEvaluationSchool());
			refundVO.setProvince(li.getProvince());
			refundVO.setRegionUserName(li.getRegionUserName());
			refundVO.setLaborCost(li.getLaborCost());
			refundVO.setMeals(li.getMeals());
			refundVO.setTrafficExpense(li.getTrafficExpense());
			refundVO.setHotelExpense(li.getHotelExpense());
			refundVO.setPostage(li.getPostage());
			refundVO.setTrafficExpenseMax(li.getTrafficExpenseMax());
			refundVO.setSumExpense(li.getSumExpense());
			refundVO.setBankAccount(li.getBankAccount());
			refundVO.setBankOfDeposit(li.getBankOfDeposit());
			refundVO.setExpertOrgName(li.getExpertOrgName());
			refundVO.setRemarks(li.getRemarks());
			refundVO.setEvaluationNum(li.getEvaluationNum());
			refundVO.setLaborCostAveragePrice(li.getLaborCostAveragePrice());
			refundVO.setMobile(li.getMobile());
			if (li.getExamFeeIf()!=null){ //查询证书等级并导出
				ExaminationCostDO examinationCostDO = examinationCostService.selectById(li.getExamFeeIf());
				refundVO.setProfile(examinationCostDO.getProfile());
			}
			//其它费用
			refundVO.setOtherCost(li.getOtherCost());
//			if(li.getRefundType()==1){
//				refundVO.setRefundType("对私");
//			}else {
//				refundVO.setRefundType("对共");
//			}
			listFile.add(refundVO);
			if(is==8||is==9||is==18||is==19){
				li.setExport(1);
				li.setDeriveTime(new Date());
				refundService.updateById(li);
			}

			for (RefundDO refundDO:list){
				//如果导出的数据中有不同的批次
				if (!batchId.equals(refundDO.getBatchId())){
					batchId = 0;
				}
			}

		}

		String msg1 = "";

		//不等于0说明都为一个批次就要拼接数据了
		if (batchId !=0){
			ExaminationCostDO examinationCostDO=examinationCostService.selectById(list.get(0).getExamFeeIf());
			msg1 = "考评人数：" + examinationCostDO.getStuNum() + " " + "证书等级：" + examinationCostDO.getProfile() + " ";
		}

		if (batchId == 0){
			Integer rs = 0;
			List<RefundDO> refundDOS = batchRemoveDuplicates(list);
			for (int i=0;i<refundDOS.size();i++){
				ExaminationCostDO examinationCostDO=examinationCostService.selectById(refundDOS.get(i).getExamFeeIf());
				rs = rs + examinationCostDO.getStuNum();
			}
			msg1 = "考试总人数：" + rs + " ";
		}



//		//导出操作
//		EasyPoiUtil.exportExcel(listFile, "考试费劳务费信息表", "劳务费信息（批量）", RefundVO.class, "考试费劳务费信息（批量）", response);

		ExportParams exportParams =new ExportParams();
		Date date=new Date();
		SimpleDateFormat sdf =new SimpleDateFormat("yyyy-MM-dd");

		ExpenseTotalBO expenseTotalBO = refundService.moneyTotal(map);
		expenseTotalBO = bigDecimalDef(expenseTotalBO);

		String msg= msg1 +
				"导出时间："+sdf.format(date)+" " +
				" （劳务费合计："+expenseTotalBO.getLaborCostTotal()+
				"） （餐费费合计："+expenseTotalBO.getMealsTotal()+"） （市内交通费合计："+expenseTotalBO.getTrafficExpenseTotal()+
				"） （住宿费合计："+expenseTotalBO.getHotelExpenseTotal()+"） （邮费合计："+expenseTotalBO.getPostageTotal()+
				"） （大交通费合计："+expenseTotalBO.getTrafficExpenseMaxTotal()+"） （其它费用："+expenseTotalBO.getOtherCostTotal()+
				"）" +
				"	总合计："+expenseTotalBO.getSumExpenseTotal();

		exportParams.setSecondTitle(msg);

		setUserRefundwVO(listFile);




		String exceltitle ="";
		list = examFeeIfRemoveDuplicates(list);
		if (list.size()<10) { //超过十个考试批次就不进行下面的操作了。
			for (int i = 0; i < list.size(); i++) {
				ExaminationCostDO examinationCostDO = examinationCostService.selectById(list.get(i).getExamFeeIf());
				if (StringUtil.notEmpty(examinationCostDO.getExaminationBatchId())) {
					String[] array = splitStrArray(examinationCostDO.getExaminationBatchId());
					if (array.length > 0) {
						for (int j = 0; j < array.length; j++) {
							if (StringUtil.notEmpty(array[j])) {
								String name = examinationBatchService.selectById(array[j]).getName();
								if ("".equals(exceltitle)) {
									exceltitle = name;
								} else {
									exceltitle = exceltitle + "," + name;
								}
							}
						}
					}
				}
			}
		}

		if (!"".equals(exceltitle)){
			exceltitle = "费劳务费信息表 (考试批次："+ exceltitle + ")";
		}else {
			exceltitle = "费劳务费信息表";
		}

		EasyPoiUtil.exportExcel2(listFile, exceltitle, "劳务费信息表", RefundVO.class, "劳务费信息表", response,exportParams);
	}






	public static String[] splitStrArray(String str) {
		if (str != null) {
			return str.split(",");
		}
		return null;
	}




	//剔除重复batchid
	public List<RefundDO>  batchRemoveDuplicates(List<RefundDO> refundDOS){
		List<RefundDO> rstList = new ArrayList<>();
		rstList.add(refundDOS.get(0));
		Integer batchId = refundDOS.get(0).getBatchId(); //拿到一个批次id
		for (int i=0;i<refundDOS.size();i++){
			Integer forBatchID = refundDOS.get(i).getBatchId();
			if (String.valueOf(batchId).equals(String.valueOf(forBatchID))){
				continue;
			}
			rstList.add(refundDOS.get(i));
			batchId = forBatchID;
		}
		return rstList;
	}



	public List<RefundDO>  examFeeIfRemoveDuplicates(List<RefundDO> refundDOS){
		List<RefundDO> rstList = new ArrayList<>();
		rstList.add(refundDOS.get(0));
		String examFeeIfv = refundDOS.get(0).getExamFeeIf();
		for (int i=0;i<refundDOS.size();i++){
			String examFeeIf = refundDOS.get(i).getExamFeeIf();
			if (examFeeIfv.equals(examFeeIf)){
				continue;
			}
			rstList.add(refundDOS.get(i));
			examFeeIfv = examFeeIf;
		}
		return rstList;
	}




	/**
	 * 查询对应的考试费信息
	 *
	 */
	@RequestMapping("/selectCost")
	@RequiresPermissions("jzweb:refund:import")
	@ResponseBody
	public Result<?> selectCost(@RequestParam(required = false,defaultValue = "1")int pageNumber, @RequestParam(required = false,defaultValue = "10")int pageSize, String name,Integer year) {
		// 查询列表数据
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//查询所有用户所属权限
		Integer is = userRoleService.userRolenum(this.getUserId());
		Map map=new HashMap();
		Long chOO1=0l;
		Long chOO2=0l;
		List<RoleDO>  listRole=roleService.findAll();
		List<String> lists=new ArrayList();
		String userID=this.getUserId().toString();
		if(is==8||is==9||is==18||is==19){
			lists.add(userID);
		}if(is==6){
			List lists1=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场一部")||roleDO.getRoleName().equals("市场一部管理员")){
					chOO1=roleDO.getId();
					lists1.add(chOO1);
					//break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.in("roleId",lists1);
			//Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);
			List <UserRoleDO> userRoleDOS =userRoleService.selectList(wrapper1);
			//List<UserRoleDO> userRoleDOS=	page1.getRecords();
			for(UserRoleDO users:userRoleDOS){
				lists.add(users.getUserId().toString());
			}
			map.put("list1",lists);
		}else if(is==7){
			List lists1=new ArrayList();

			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场二部")||roleDO.getRoleName().equals("市场二部管理员")){
					chOO1=roleDO.getId();
					lists1.add(chOO1);
					//break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.in("roleId",lists1);
			List <UserRoleDO> userRoleDOS =userRoleService.selectList(wrapper1);
			for(UserRoleDO users:userRoleDOS){
				lists.add(users.getUserId().toString());
			}
			map.put("list1",lists);
		}

		Page<Map<Object,Object>> list1=examinationCostService.selectSchool(pageNumber,pageSize,name,lists,year);

		return Result.ok(list1);

	}


	/**
	 * 考试费用详情表导入
	 *
	 * @param file excel文件,refundType:返费类型（0对公，1对私）
	 *
	 */
	@Log("考试费用详情表导入")
	@PostMapping("/import")
	@ResponseBody
	@Transactional
	@RequiresPermissions("jzweb:refund:import")
	public Result<?> importExcel(@RequestParam("file") MultipartFile file,Integer year,String examFeeIf) {
		//---------------------------------检测导入信息及条件-----------------------------------------
		//第一步--判断文件格式
		if (!"application/vnd.ms-excel".equals(file.getContentType())) {
			return Result.fail("文件格式错误，请选择.xls文件");
		}
		if(StringUtils.isNullOrEmpty(examFeeIf)){
			return Result.fail("请选择考试费学校");
		}

		ExaminationCostDO examinationCostDO=examinationCostService.selectById(examFeeIf);

		if(null != examinationCostDO.getImportState()){
			if ("1".equals(String.valueOf(examinationCostDO.getImportState()))){
				return Result.fail("一个学校的考试批次只能导入一次，请勿重复导入！");
			}
		}

		if(examinationCostDO!=null){
			if(!examinationCostDO.getYear().toString().equals(year.toString())){
				return Result.fail("所选考试批次非:"+year+"批次");
			}
		}

		if (examinationCostDO.getIsEnelexamen() !=null){
			if(examinationCostDO.getIsEnelexamen().equals("1")){
				return Result.fail("包含免,补的考试批次均不能导入劳务费！");
			}
		}


//		if(refundType==null){
//			return Result.fail("请选择返费类型");
//		}

		//第二步--解析文件获得数据
		List<RefundVO> list = EasyPoiUtil.importExcel(file, 1, 1, RefundVO.class);
		System.out.println("解析后的数据++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"+list);
		if (list.size() == 0) {
			return Result.fail("Excel数据为空，请完善");
		}

		for(int i=0;i<list.size();i++){
//			int p=0;
			List<ErrorCodeVo> list1 = new ArrayList<>();
//			StringBuilder sb = new StringBuilder();
//			for(int j=0;j<list.size();j++){
//				if(list.get(i).getBankAccount().equals(list.get(j).getBankAccount())){
//					p++;
//				}
//				if(p>1){
//					sb.append(list.get(i).getBankAccount() + "卡号在表格中重复！" + ";");
//					ErrorCodeVo errorCodeVo = new ErrorCodeVo();
//					errorCodeVo.setSeq(1);
//					errorCodeVo.setErrorCode(sb.toString());
//					list1.add(errorCodeVo);
//					break;
//				}
//			}
			if(list1.size()>0){

				JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(list1));
				//将list1存到缓存中
				EhCacheUtil.put("refundService" + this.getUserId(), jsonArray);
				return Result.build(EnumErrorCode.FileImportError.getCode(), EnumErrorCode.FileImportError.getMsg());
			}
		}

		//---------------------------------验证数据并导入-----------------------------------------
		//数据该表第三行，第一行标题，第二行表头
		int startRow = 3;
		int cout = 1;//错误信息计数
		List<RefundDO> examCostList = new ArrayList<>();
		List<ErrorCodeVo> list1 = new ArrayList<>();
		List<RefundVO> cerUtilsVos = new ArrayList<>();

		//插入前先去获取数据库最大批次号
		int batchId = refundService.batchMax();

		//一批次费用合计
		BigDecimal total= new BigDecimal(0.0);

		for (int i = 0; i < list.size(); i++) {
			RefundDO refundDO=new RefundDO();
			StringBuilder sb = new StringBuilder();
			if(StringUtils.isNullOrEmpty(list.get(i).getExpertName())){
				sb.append("第" + (i + startRow) + "专家姓名未填写，请完善！" + ";");
			}else if (StringUtils.isNullOrEmpty(list.get(i).getMobile())){
				sb.append("第" + (i + startRow) + "手机号未填写，请完善！" + ";");
			} else if(StringUtils.isNullOrEmpty(list.get(i).getExpertIdCard())){
				sb.append("第" + (i + startRow) + "专家身份证号码未填写，请完善！" + ";");
			}else if(StringUtils.isNullOrEmpty(list.get(i).getExpertType())){
				sb.append("第" + (i + startRow) + "行区域专家类型未填写，请完善！" + ";");
			}else if(StringUtils.isNullOrEmpty(list.get(i).getExpertOrgName())){
				sb.append("第" + (i + startRow) + "行专家所属机构未填写，请完善！" + ";");
			}else if(null == list.get(i).getLaborCost()){
				sb.append("第" + (i + startRow) + "行劳务费未填写，请完善！" + ";");
			}else if(null == list.get(i).getMeals()){
				sb.append("第" + (i + startRow) + "行餐费未填写，请完善！" + ";");
			}else if(null == list.get(i).getTrafficExpense()){
				sb.append("第" + (i + startRow) + "行交通费未填写，请完善！" + ";");
			}else if(null == list.get(i).getHotelExpense()){
				sb.append("第" + (i + startRow) + "行住宿费未填写，请完善！" + ";");
			}else if(null == list.get(i).getPostage()){
				sb.append("第" + (i + startRow) + "行邮费未填写，请完善！" + ";");
			}else if (null == list.get(i).getOtherCost()){
				sb.append("第" + (i + startRow) + "行其它费用未填写，请完善！" + ";");
			}else if(StringUtils.isNullOrEmpty(list.get(i).getBankAccount())){
				sb.append("第" + (i + startRow) + "行银行账户未填写，请完善！" + ";");
			}else if(StringUtils.isNullOrEmpty(list.get(i).getBankOfDeposit())){
				sb.append("第" + (i + startRow) + "行开户银行未填写，请完善！" + ";");
//			}else if(StringUtils.isNullOrEmpty(list.get(i).getRefundType())) {
//				sb.append("第" + (i + startRow) + "行返费类型（对公/对私未填写）！" + ";");

//			}else if(list.get(i).getRefundType().equals("对公")||list.get(i).getRefundType().equals("对私")){
//				sb.append("第" + (i + startRow) + "行返费类型（对公/对私填写不规范，正确填写未：对公  对私）！" + ";");
//			}
//			String map= archivesService.schoolNmae(list.get(i).getEvaluationSchool());
//			if(map==null){
//				sb.append("第" + (i + startRow) + list.get(i).getEvaluationSchool()+"在学校档案系统中未找到！" + ";");
//			}
			}
			if (sb.length() > 0) {
				ErrorCodeVo errorCodeVo = new ErrorCodeVo();
				errorCodeVo.setSeq(cout);
				cout += 1;
				errorCodeVo.setErrorCode(sb.toString());
				list1.add(errorCodeVo);
			}
			//批次id
			refundDO.setBatchId(batchId);
			refundDO.setBankAccount(list.get(i).getBankAccount());
			//默认是未确定未退回的数据
			refundDO.setConfirmState(0);
			refundDO.setReturnState(0);
			refundDO.setOtherCost(list.get(i).getOtherCost());
			refundDO.setExpertOrgName(list.get(i).getExpertOrgName()); //专家所属机构
			refundDO.setExamFeeIf(examFeeIf);
			refundDO.setExpertName(list.get(i).getExpertName());
			refundDO.setExpertIdCard(list.get(i).getExpertIdCard());
			refundDO.setExpertType(list.get(i).getExpertType());
			//劳务费默认对私
			refundDO.setRefundType(1);
			refundDO.setBankOfDeposit(list.get(i).getBankOfDeposit());
			//refundDO.setEvaluationNum(list.get(i).getEvaluationNum());
			//refundDO.setEvaluationSchool(list.get(i).getEvaluationSchool());
			//餐费
			refundDO.setMeals(list.get(i).getMeals());
			refundDO.setMobile(list.get(i).getMobile()); //专家手机号

			//剔除空元素
			for (int j =0;j<list.size();j++){
				RefundVO refundVO = list.get(j);
				//如果专家姓名类型与银行卡信息都为null那么就认为它是一条空数据
				if (refundVO.getExpertName()==null&&refundVO.getExpertType()==null&&refundVO.getBankAccount()==null&&refundVO.getBankOfDeposit()==null){
					list.remove(j);
					j--;
				}
			}


			BigDecimal sum=list.get(i).getMeals().
					 add(list.get(i).getLaborCost().add(list.get(i).getTrafficExpense())
							 .add(list.get(i).getTrafficExpenseMax())
							 .add(list.get(i).getHotelExpense())
							 .add(list.get(i).getPostage()))
					         .add(list.get(i).getOtherCost())
					;
			refundDO.setYear(year);
			//交通费
			refundDO.setTrafficExpense(list.get(i).getTrafficExpense());
			//最大交通费
			refundDO.setTrafficExpenseMax(list.get(i).getTrafficExpenseMax());
			//住宿费
			refundDO.setHotelExpense(list.get(i).getHotelExpense());

			if(examinationCostDO!=null){
				refundDO.setEvaluationSchool(examinationCostDO.getOrgName()!=null?examinationCostDO.getOrgName():null);
				refundDO.setEvaluationTime(examinationCostDO.getExaminationDate());
				refundDO.setEvaluationNum(examinationCostDO.getStuNum());
			}

			//合计暂时放着
			refundDO.setSumExpense(sum);
			refundDO.setCreateTime(new Date());
			refundDO.setRefundRrNot(0);
			refundDO.setPostage(list.get(i).getPostage());
			refundDO.setRemarks(list.get(i).getRemarks());

			refundDO.setHotelExpense(list.get(i).getHotelExpense());
//			if(list.get(i).getRefundType().equals("对公")){
//				refundDO.setRefundType(0);
//			}else {
//				refundDO.setRefundType(1);
//			}
			refundDO.setLaborCost(list.get(i).getLaborCost());
			examCostList.add(refundDO);
		}

		//计算合计
		for(RefundDO re:examCostList){
			total = total.add(re.getSumExpense());
		}

		//实际考试人数
		Integer stuNum = examinationCostDO.getStuNum();

		//劳务费均价计算 合计金额 / 考试实际人数
		BigDecimal laborCostAveragePrice = total.divide(new BigDecimal(stuNum),3,BigDecimal.ROUND_HALF_UP);

		//同一考试批次均价相同
		for(RefundDO re:examCostList){
			re.setLaborCostAveragePrice(laborCostAveragePrice);
		}
		System.out.println("+++++++++++++++++++++要添加的数据+++++++++++++++++++++++++++"+examCostList);
		if (list1.size() == 0) {
			refundService.insertBatch(examCostList);
			//成功导入后 import状态为1即不可再导入
			examinationCostDO.setImportState(1);
			examinationCostService.updateById(examinationCostDO);
			return Result.ok("成功导入" + list.size() + "条数据");
		}else{
			JSONArray jsonArray = JSONArray.parseArray(JSON.toJSONString(list1));
			//将list1存到缓存中
			EhCacheUtil.put("refundService" + this.getUserId(), jsonArray);
			return Result.build(EnumErrorCode.FileImportError.getCode(), EnumErrorCode.FileImportError.getMsg());
		}
	}
	/**
	 * 导出错误信息
	 *
	 * @param request
	 * @param response
	 * @throws Exception
	 * @author kl
	 */
	@Log("导出错误信息")
	@GetMapping("/importError")
	@ResponseBody
	@Transactional
	@RequiresPermissions("jzweb:refund:import")
	public void importError(HttpServletRequest request, HttpServletResponse response) throws Exception {
		// 告诉浏览器用什么软件可以打开此文件
		response.setHeader("content-Type", "application/vnd.ms-excel");
		// 下载文件的默认名称
		response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode("考试返费导入错误信息", "UTF-8") + ".xls");
		//编码
		response.setCharacterEncoding("UTF-8");
		String jsonArray = EhCacheUtil.get("refundService" + this.getUserId()).toString();
		JSONArray arrayList = JSONArray.parseArray(jsonArray);
		//转换为目标对象list
		List<ErroeDownVo> groupList = JSONObject.parseArray(arrayList.toJSONString(), ErroeDownVo.class);
		Workbook workbook = ExcelExportUtil.exportExcel(new ExportParams(), ErroeDownVo.class, groupList);
		workbook.write(response.getOutputStream());
	}



	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("jzweb:refund:refund")
	public Result<Map<String,Object>> list(RefundDO refundDTO,@RequestParam(required = false,defaultValue = "1")int pageNumber, @RequestParam(required = false,defaultValue = "10")int pageSize){
		// 查询列表数据
		Long roleId=0l;
		//1 订单发布角色  2 订单审核专员   3 仓库审核专员  4超级用户角色  roleName
		//查询所有用户所属权限
		Integer is = userRoleService.userRolenum(this.getUserId());
		Map map=new HashMap();
		List<RoleDO>  listRole=roleService.findAll();
		Long chOO1=0l;
		Long chOO2=0l;
		if(is==6){
			List lists=new ArrayList();
			List list=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场一部")||roleDO.getRoleName().equals("市场一部管理员")){
					chOO1=roleDO.getId();
					lists.add(chOO1);
					//break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.in("roleId",lists);
			//Page<UserRoleDO> page1 =	userRoleService.selectPage(getPages(UserRoleDO.class), wrapper1);
			List <UserRoleDO> userRoleDOS =userRoleService.selectList(wrapper1);
			//List<UserRoleDO> userRoleDOS=	page1.getRecords();
			for(UserRoleDO users:userRoleDOS){
				list.add(users.getUserId());
			}
			map.put("list1",list);
		}else if(is==7){
			List lists=new ArrayList();
			List list=new ArrayList();
			for(RoleDO roleDO:listRole){
				if(roleDO.getRoleName().equals("市场二部")||roleDO.getRoleName().equals("市场二部管理员")){
					chOO1=roleDO.getId();
					lists.add(chOO1);
					//break;
				}
			}
			EntityWrapper<UserRoleDO> wrapper1 = new EntityWrapper<>();

			wrapper1.in("roleId",lists);
			List <UserRoleDO> userRoleDOS =userRoleService.selectList(wrapper1);
			for(UserRoleDO users:userRoleDOS){
				list.add(users.getUserId());
			}
			map.put("list1",list);
		}else if(is==8){
			map.put("list2",this.getUserId().toString());

		}else if(is==9){

			map.put("list2",this.getUserId().toString());
		}else if(is==18){
			map.put("list2",this.getUserId().toString());

		}else if(is==19){

			map.put("list2",this.getUserId().toString());
		}

		map.put("pageNumber",pageNumber);
		map.put("pageSize",pageSize);
		map.put("id1",refundDTO.getId1());
		map.put("refundRrNot",refundDTO.getRefundRrNot());
		map.put("batchId",refundDTO.getBatchId());
		map.put("batchId2",refundDTO.getBatchId2());
		map.put("year",refundDTO.getYear());
		map.put("province",refundDTO.getProvince());
		map.put("expertName",refundDTO.getExpertName());
		map.put("expertIdCard",refundDTO.getExpertIdCard());
		//map.put("refundRrNot",refundDTO.getRefundRrNot());
		map.put("evaluationSchool",refundDTO.getSchoolName());
		map.put("regionUserName",refundDTO.getRegionUserName());
		//map.put("export",1);
			map.put("examStartDate",StringUtil.notEmpty(refundDTO.getExamStartDate())?refundDTO.getExamStartDate()+" 00:00:00":refundDTO.getExamStartDate());

			map.put("examEndDate",StringUtil.notEmpty(refundDTO.getExamEndDate())?refundDTO.getExamEndDate()+" 00:00:00":refundDTO.getExamEndDate());

//		// 查询列表数据
//		Page<RefundDO> page = refundService.selectPage(getPage(RefundDO.class),
//					refundService.convertToEntityWrapper().orderBy("id", false).eq("year",refundDTO.getYear()));
		Page<RefundDO> page =new Page<>();
		page.setCurrent(pageNumber);
		Integer integer=refundService.listRefundCount(map);
		page.setTotal(integer);
		page.setSize(pageSize);
		List list = new ArrayList();

		List<RefundDO> list1=refundService.listRefund(map);
		//定义总价对象集合
		List<ExpenseTotalBO> expenseTotalBOS =new ArrayList<>();
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		for (int i = 0; i < list1.size(); i++) {
			ExpenseTotalBO expenseTotalBO =new ExpenseTotalBO();

			RefundDO obj =new RefundDO();
			obj=list1.get(i);
			obj.setEvaluationTimes(list1.get(i).getEvaluationTime()!=null?sdf.format(list1.get(i).getEvaluationTime()):null);

			list.add(obj);
			expenseTotalBOS.add(expenseTotalBO);
		}


		//金额计算
		ExpenseTotalBO expenseTotalBO = refundService.moneyTotal(map);
		expenseTotalBO = bigDecimalDef(expenseTotalBO);


		page.setRecords(list);

		Map<String,Object> retMap =new HashMap();
		retMap.put("page",page);
		retMap.put("moneyTotal",expenseTotalBO);
        return Result.ok(retMap);
	}


	//费用默认值
	private ExpenseTotalBO bigDecimalDef(ExpenseTotalBO expenseTotalBO){
		if (null==expenseTotalBO){
			expenseTotalBO=new ExpenseTotalBO();
			expenseTotalBO.setSumExpenseTotal(new BigDecimal(0.0));
			expenseTotalBO.setMealsTotal(new BigDecimal(0.0));
			expenseTotalBO.setHotelExpenseTotal(new BigDecimal(0.0));
			expenseTotalBO.setPostageTotal(new BigDecimal(0.0));
			expenseTotalBO.setTrafficExpenseMaxTotal(new BigDecimal(0.0));
			expenseTotalBO.setTrafficExpenseTotal(new BigDecimal(0.0));
			expenseTotalBO.setLaborCostTotal(new BigDecimal(0.0));
			expenseTotalBO.setOtherCostTotal(new BigDecimal(0.0));
			return expenseTotalBO;
		}
		if (null==expenseTotalBO.getSumExpenseTotal()){
			expenseTotalBO.setSumExpenseTotal(new BigDecimal(0.0));
		}
		if (null==expenseTotalBO.getOtherCostTotal()){
			expenseTotalBO.setOtherCostTotal(new BigDecimal(0.0));
		}
		if (null==expenseTotalBO.getTrafficExpenseMaxTotal()){
			expenseTotalBO.setTrafficExpenseMaxTotal(new BigDecimal(0.0));
		}
		if (null==expenseTotalBO.getPostageTotal()){
			expenseTotalBO.setPostageTotal(new BigDecimal(0.0));
		}
		if (null==expenseTotalBO.getHotelExpenseTotal()){
			expenseTotalBO.setHotelExpenseTotal(new BigDecimal(0.0));
		}
		if (null==expenseTotalBO.getTrafficExpenseTotal()){
			expenseTotalBO.setTrafficExpenseTotal(new BigDecimal(0.0));
		}
		if (null==expenseTotalBO.getLaborCostTotal()){
			expenseTotalBO.setLaborCostTotal(new BigDecimal(0.0));
		}
		if (null==expenseTotalBO.getMealsTotal()){
			expenseTotalBO.setMealsTotal(new BigDecimal(0.0));
		}
		return expenseTotalBO;
	}


	
	@GetMapping("/add")
	@RequiresPermissions("jzweb:refund:add")
	String add(Integer year,Model model){
		model.addAttribute("year",year);
	    return "jzweb/refund/add";
	}

	@GetMapping("/edit/{id}")
	@RequiresPermissions("jzweb:refund:edit")
	String edit(@PathVariable("id") Long id,Model model){
		RefundDO refund = refundService.selectById(id);
		SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
		refund.setEvaluationTimes(sdf.format(refund.getEvaluationTime()));

		model.addAttribute("refund", refund);
	    return "jzweb/refund/edit";
	}
	
	@Log("添加")
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("jzweb:refund:add")
	public Result<String> save( RefundDO refund) {
		if (StringUtils.isNullOrEmpty(refund.getExpertName())) {
			return Result.fail("专家姓名未填写，请完善！");
		}else if (StringUtils.isNullOrEmpty(refund.getExpertIdCard())) {
			return Result.fail("专家身份证号码未填写，请完善！");
		}else if (StringUtils.isNullOrEmpty(refund.getMobile())) {
			return Result.fail("电话未填写，请完善！");
		} else if (StringUtils.isNullOrEmpty(refund.getExpertType())) {
			return Result.fail("专家类型未填写，请完善！");
		} else if (StringUtils.isNullOrEmpty(refund.getExpertOrgName())) {
			return Result.fail("专家所属机构未填写，请完善！");
		} else if (null == refund.getLaborCost()) {
			return Result.fail("劳务费未填写，请完善！");
		} else if (null == refund.getMeals()) {
			return Result.fail("餐费未填写，请完善！");
		} else if (null == refund.getTrafficExpense()) {
			return Result.fail("市内交通费未填写，请完善！");
		}else if (null == refund.getTrafficExpenseMax()){
			return Result.fail("大交通费未填写，请完善！");
		}else if(null == refund.getHotelExpense()){
			return Result.fail("住宿费未填写，请完善！");
		}else if(null == refund.getPostage()){
			return Result.fail("邮费未填写，请完善！");
		}else if (null == refund.getOtherCost()){
			return Result.fail("其它费用未填写，请完善！");
		}else if(StringUtils.isNullOrEmpty(refund.getBankAccount())){
			return Result.fail("银行账户未填写，请完善！");
		}else if(StringUtils.isNullOrEmpty(refund.getBankOfDeposit())) {
			return Result.fail("开户银行未填写，请完善！");
		}

		if (refund.getBatchId() != null){
			if (refund.getBatchId()<100000){
				return Result.fail("批次id不能小于100000");
			}
		}

		//如果批次id为空则进行获取最大批次id
		if (null == refund.getBatchId()){
			int batchId = refundService.batchMax();
			refund.setBatchId(batchId);
		}

		//新数据默认未确认，未退回状态
		refund.setConfirmState(0);
		refund.setReturnState(0);

		//劳务费默认对私
		refund.setRefundType(1);

		ExaminationCostDO examinationCostDO=examinationCostService.selectById(refund.getExamFeeIf());

		if(examinationCostDO!=null){
			refund.setEvaluationSchool(examinationCostDO.getOrgName()!=null?examinationCostDO.getOrgName():null);
			refund.setEvaluationTime(examinationCostDO.getExaminationDate());
			refund.setEvaluationNum(examinationCostDO.getStuNum());
		}

		BigDecimal sum=refund.getMeals().
				add(refund.getLaborCost().add(refund.getTrafficExpense())
						.add(refund.getTrafficExpenseMax())
						.add(refund.getHotelExpense())
						.add(refund.getPostage()))
				.add(refund.getOtherCost());
		//合计暂时放着
		refund.setSumExpense(sum);
		refund.setCreateTime(new Date());
		refund.setRefundRrNot(0);
		refundService.insert(refund);
        return Result.ok();
	}
	
	@Log("修改")
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("jzweb:refund:edit")
	public Result<String>  update( RefundDO refund){
		RefundDO refundDO=refundService.selectById(refund.getId());



		//获取当前用户权限
		Integer is = userRoleService.userRolenum(this.getUserId());

			if(refundDO.getRefundRrNot()==1){
				return Result.fail("已经返费的数据不允许操作！");
			}
			if (refundDO.getConfirmState()==1){
				//不是市场总监
				if (is!=12){
					return Result.fail("当前角色无权限修改已经确认的数据！");
				}
			}

		//银行卡号
		String bankAccount = refundDO.getBankAccount();
		if (!bankAccount.equals(refund.getBankAccount())){ //如果不是输入的银行卡号
			EntityWrapper<RefundDO> wrapper = new EntityWrapper<>();
			wrapper.eq("bank_account",refund.getBankAccount());
			List<RefundDO> refundDOS = refundService.selectList(wrapper);
			if (refundDOS.size()>0){ //表明银行卡存在
				if ("10".equals(String.valueOf(is))||"11".equals(String.valueOf(is))||"8".equals(String.valueOf(is))
						||"9".equals(String.valueOf(is))||"1".equals(String.valueOf(is))||"3".equals(String.valueOf(is))||"5".equals(String.valueOf(is))){
					return Result.fail("当前角色无权修改银行卡重复的数据！");
				}
			}
		}

		if(!StringUtils.isNullOrEmpty(refund.getEvaluationTimes())){
			SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd ");
			try {
				refund.setEvaluationTime(sdf.parse(refund.getEvaluationTimes()+" 00:00:00"));
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}

		BigDecimal sum=refund.getMeals().
				add(refund.getLaborCost().add(refund.getTrafficExpense())
						.add(refund.getTrafficExpenseMax())
						.add(refund.getHotelExpense())
						.add(refund.getPostage()))
				.add(refund.getOtherCost())
				;
		refund.setSumExpense(sum);
		boolean update = refundService.updateById(refund);

		/***
		 * 劳务费均价修改
		 */
		if (update){
			RefundDO refundDOLaborCostAveragePrice = refundService.selectOne(refund);
			EntityWrapper<RefundDO> wrapperBatId = new EntityWrapper<>();
			wrapperBatId.eq("batch_id",refundDOLaborCostAveragePrice.getBatchId());
			//获取同一批次的数据
			List<RefundDO> refundDOS = refundService.selectList(wrapperBatId);
			//一批次费用合计
			BigDecimal total= new BigDecimal(0.0);
			//计算合计
			for(RefundDO re:refundDOS){
				total = total.add(re.getSumExpense());
			}
			ExaminationCostDO examinationCostDO=examinationCostService.selectById(refundDOLaborCostAveragePrice.getExamFeeIf());
			//实际考试人数
			Integer stuNum = examinationCostDO.getStuNum();
			//劳务费均价计算 合计金额 / 考试实际人数
			BigDecimal laborCostAveragePrice = total.divide(new BigDecimal(stuNum),3,BigDecimal.ROUND_HALF_UP);
			for (int i=0;i<refundDOS.size();i++){
				refundDOS.get(i).setLaborCostAveragePrice(laborCostAveragePrice);
			}
			refundService.updateBatchById(refundDOS);
			//修改劳务费均价
		}

		return update ? Result.ok() : Result.fail();
	}
	
	@Log("删除")
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("jzweb:refund:remove")
	public Result<String>  remove( Long id){
		RefundDO refundDO=refundService.selectById(id);

		//获取当前用户权限
		Integer is = userRoleService.userRolenum(this.getUserId());
		if (is != 4) {
			if (refundDO.getConfirmState() == 1) {
				//不是市场总监
				if (is != 12) {
					return Result.fail("当前角色无权限删除已经确认的数据！");
				}
			}

			if (refundDO.getRefundRrNot() == 1) {
				return Result.fail("已经返费的数据不允许操作！");
			}
		}
		refundService.deleteById(id);

		logService.saveOperationLog(new LogBO().setOperation("2022劳务费信息管理/劳务费删除").setUserId(String.valueOf(this.getUserId())));
        return Result.ok();
	}
	
	@Log("批量删除")
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("jzweb:refund:batchRemove")
	public Result<String>  refunds(@RequestParam("ids[]") Long[] ids){

		List<RefundDO> refundDOS = refundService.selectBatchIds(Arrays.asList(ids));

		for (int i=0;i<refundDOS.size();i++){
			if (refundDOS.get(i).getConfirmState() == 1){ //已确认
				return Result.fail("包含已确认的数据，无法批量删除！");
			}
		}

		refundService.deleteBatchIds(Arrays.asList(ids));
		return Result.ok();
	}


	@Log("劳务费确认")
	@PostMapping("/batchConfirm")
	@ResponseBody
	@RequiresPermissions("jzweb:refund:batchConfirm")
	public Result<String>  confirmCost(@RequestParam("id") Long confirmId){
		//目前是单个确认，考虑到以后可能是批量
		Long[] ids =new Long[10];
		ids[0]=confirmId;
		List<RefundDO> refundDOList = refundService.selectBatchIds(Arrays.asList(ids));
		for (RefundDO refundDO:refundDOList){
			if (1==refundDO.getConfirmState()){
				return Result.fail("请勿重复确认！");
			}
			if (1==refundDO.getRefundRrNot()){
				return Result.fail("已返费数据不能确认！");
			}
		}

		if (ids.length==0){
			return Result.build(500,"id不能为空");
		}
		List<RefundDO> refundDOS = new ArrayList<>();
		Arrays.stream(ids).forEach(id->{
			RefundDO refundDO =new RefundDO();
			refundDO.setId(id).setConfirmState(1).setConfirmDate(new Date()).setRefundRrNot(0);
			refundDOS.add(refundDO);
		});
		boolean ret = refundService.updateBatchById(refundDOS);
		if (!ret){
			return Result.fail();
		}
		return Result.ok();
	}


	@Log("劳务费批量确认")
	@PostMapping("/batchConfirm2")
	@ResponseBody
	@RequiresPermissions("jzweb:refund:batchConfirm2")
	public Result<String>  confirmCost2(@RequestParam("ids[]") Long[] ids){
		List<RefundDO> refundDOList = refundService.selectBatchIds(Arrays.asList(ids));
		for (RefundDO refundDO:refundDOList){
			if (1==refundDO.getConfirmState()){
				return Result.fail("请勿重复确认！");
			}
			if (1==refundDO.getRefundRrNot()){
				return Result.fail("已返费数据不能确认！");
			}
		}

		if (ids.length==0){
			return Result.build(500,"id不能为空");
		}
		List<RefundDO> refundDOS = new ArrayList<>();
		Arrays.stream(ids).forEach(id->{
			RefundDO refundDO =new RefundDO();
			refundDO.setId(id).setConfirmState(1).setConfirmDate(new Date()).setRefundRrNot(0);
			refundDOS.add(refundDO);
		});
		boolean ret = refundService.updateBatchById(refundDOS);
		if (!ret){
			return Result.fail();
		}
		return Result.ok();
	}




	@Log("返费退回")
	@PostMapping("/returnCost")
	@ResponseBody
	@RequiresPermissions("jzweb:refund:returnCost")
	public Result<String>  rejectCost(@RequestParam("id") String id,@RequestParam("returnExplain") String returnExplain){

		RefundDO ref = refundService.selectById(id);

		if (ref.getConfirmState()==0){
			return Result.fail("请先确认后再进行退回操作！");
		}

		if (1==ref.getRefundRrNot()){
			return Result.fail("已返费数据无法退回！");
		}
		if (2==ref.getRefundRrNot()){
			return Result.fail("请勿重复退回！");
		}


		if (StringUtil.isNull(id)){
			return Result.build(500,"id不能为空");
		}
		RefundDO refundDO =new RefundDO();
		refundDO.setId(Long.valueOf(id)).setRefundRrNot(2).setReturnDate(new Date()).setReturnState(1).setReturnExplain(returnExplain).setConfirmState(0);
		boolean ret = refundService.updateById(refundDO);
		if (!ret){
			return Result.fail();
		}

		logService.saveOperationLog(new LogBO().setOperation("2022劳务费信息管理/劳务费退回").setUserId(String.valueOf(this.getUserId())));

		return Result.ok();
	}






	@Log("返费批量退回")
	@PostMapping("/returnBatchCost")
	@ResponseBody
	@RequiresPermissions("jzweb:refund:returnBatchCost")
	public Result<String>  rejectCost(@RequestParam("ids[]") String[] ids,@RequestParam("returnExplain") String returnExplain){

		if (ids.length<1){
			return Result.build(500,"未选择数据");
		}

		List<RefundDO> updateRefundDO =new ArrayList<>();
		for (int i=0;i < ids.length;i++){
			List<RefundDO> ref = refundService.selectBatchIds(Arrays.asList(ids));

			if (ref.get(i).getConfirmState()==0){
				return Result.fail("请先确认后再进行退回操作！");
			}

			if (1==ref.get(i).getRefundRrNot()){
				return Result.fail("已返费数据无法退回！");
			}
			if (2==ref.get(i).getRefundRrNot()){
				return Result.fail("请勿重复退回！");
			}

			RefundDO refundDO =new RefundDO();
			refundDO.setId(Long.valueOf(ids[i])).setRefundRrNot(2).setReturnDate(new Date()).setReturnState(1).setReturnExplain("批量退回原因："+returnExplain).setConfirmState(0);
			updateRefundDO.add(refundDO);
		}
		boolean ret = refundService.updateBatchById(updateRefundDO);
		if (!ret){
			return Result.fail();
		}

		logService.saveOperationLog(new LogBO().setOperation("2022劳务费信息管理/劳务费批量退回").setUserId(String.valueOf(this.getUserId())));

		return Result.ok();
	}






//	//计算收益
//	private ExpenseTotalBO totalMoney(List<ExpenseTotalBO> expenseTotalBOS){
//		Function<List<ExpenseTotalBO>, ExpenseTotalBO> function =
//				new Function<List<ExpenseTotalBO>, ExpenseTotalBO>() {
//			@Override
//			public ExpenseTotalBO apply(List<ExpenseTotalBO> expenseTotalBOS) {
//				ExpenseTotalBO retExpenseTotalBO = new ExpenseTotalBO();
//				BigDecimal lbTotal = expenseTotalBOS.stream().map(
//						ExpenseTotalBO::getLaborCostTotal
//				).reduce(BigDecimal.ZERO, BigDecimal::add);
//				BigDecimal mlTotal = expenseTotalBOS.stream().map(
//						ExpenseTotalBO::getMealsTotal
//				).reduce(BigDecimal.ZERO, BigDecimal::add);
//				BigDecimal teTotal = expenseTotalBOS.stream().map(
//						ExpenseTotalBO::getTrafficExpenseTotal
//				).reduce(BigDecimal.ZERO, BigDecimal::add);
//				BigDecimal hlTotal = expenseTotalBOS.stream().map(
//						ExpenseTotalBO::getHotelExpenseTotal
//				).reduce(BigDecimal.ZERO, BigDecimal::add);
//				BigDecimal paTotal = expenseTotalBOS.stream().map(
//						ExpenseTotalBO::getPostageTotal
//				).reduce(BigDecimal.ZERO, BigDecimal::add);
//				BigDecimal temTotal = expenseTotalBOS.stream().map(
//						ExpenseTotalBO::getTrafficExpenseMaxTotal
//				).reduce(BigDecimal.ZERO, BigDecimal::add);
//				BigDecimal sumTotal = expenseTotalBOS.stream().map(
//						ExpenseTotalBO::getSumExpenseTotal
//				).reduce(BigDecimal.ZERO, BigDecimal::add);
//				retExpenseTotalBO.setLaborCostTotal(lbTotal).setMealsTotal(mlTotal)
//						.setTrafficExpenseTotal(teTotal).setHotelExpenseTotal(hlTotal).setPostageTotal(paTotal)
//						.setTrafficExpenseMaxTotal(temTotal).setSumExpenseTotal(sumTotal);
//				return retExpenseTotalBO;
//			}
//		};
//		ExpenseTotalBO restExpenseTotalBO = function.apply(expenseTotalBOS);
//		return restExpenseTotalBO;
//	}
//
//	private BigDecimal bigDecimalIsNull(BigDecimal bigDecimal){
//		return null==bigDecimal?new BigDecimal(0.00):bigDecimal;
//	}
@Log("批量返费")
@PostMapping( "/refunds")
@ResponseBody
@RequiresPermissions("jzweb:refund:refunds")
@Transactional
public Result<String>  remove(@RequestParam("ids[]") Long[] ids){

	List<RefundDO> ref = refundService.selectBatchIds(Arrays.asList(ids));
	for (RefundDO refundDO:ref){
		if (refundDO.getConfirmState()==0){
			return Result.fail("未确认数据不能进行该操作！");
		}
		if (1==refundDO.getRefundRrNot()){
			return Result.fail("已返费数据不能进行该操作！");
		}

	}
    for(int i=0;i<ref.size();i++){
        ref.get(i).setRefundRrNot(1);
        ref.get(i).setRefundTime(new Date());
    }
	System.out.println("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++要修改的数据"+ref);
	refundService.updateBatchById(ref);
	return Result.ok();
}


}
